package zjua4r.googlemap.demo;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.location.Location;
import android.view.MotionEvent;
import android.widget.Toast;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;

public class MarkerOverlay extends Overlay {
	
	GeoPoint m_currentGeoPoint;
	Location m_location;
	Bitmap m_marker;
	
	public MarkerOverlay(Bitmap marker)
	{
		super();
		this.m_marker = marker;
	}
	
	public void setLocation(Location location)
	{
		this.m_location = location;
	}
	
	public void setCurrentGeoPoint(GeoPoint point)
	{
		this.m_currentGeoPoint = point;
	}
	
	@Override
    public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) 
    {
        super.draw(canvas, mapView, shadow);
        
        if(m_currentGeoPoint == null) return true;

        //---translate the GeoPoint to screen pixels---
        Point screenPts = new Point();
        mapView.getProjection().toPixels(m_currentGeoPoint, screenPts);

        float left = screenPts.x - (m_marker.getWidth()/2);
        float top = screenPts.y - m_marker.getHeight();
        canvas.drawBitmap(m_marker, left, top, null);        
        
        String text = "维度：" +  this.m_currentGeoPoint.getLatitudeE6();       
        Paint paint = new Paint();
        //paint.setStrokeWidth(1);  
        paint.setARGB(255, 255, 0, 0);  
        //paint.setStyle(Paint.Style.STROKE);
        paint.setTextSize(18);
        
        canvas.drawText(text, screenPts.x - 30, screenPts.y + 5, paint);
    	text =	"经度" + this.m_currentGeoPoint.getLongitudeE6();
    	canvas.drawText(text, screenPts.x - 30, screenPts.y + 30, paint);
        return true;
    }    
}
